package com.sz.mes.excel.listener;

import com.diboot.core.util.BeanUtils;
import com.diboot.core.util.ContextHelper;
import com.diboot.core.util.V;
import com.sz.mes.excel.model.InstockImportModel;
import com.diboot.file.excel.listener.FixedHeadExcelListener;
import com.sz.mes.entity.Instock;
import com.sz.mes.service.InstockService;

import java.util.List;
import java.util.Map;

/**
* 入库 导入Listener定义
* @author hem
* @version 1.0
* @date 2023-06-07
* Copyright © szhs
*/
public class InstockImportListener extends FixedHeadExcelListener<InstockImportModel> {

    /**
    * 自定义校验规则
    * @param dataModelList    待保存的数据
    * @param requestParams  请求参数
    */
    @Override
    protected void additionalValidate(List<InstockImportModel> dataModelList, Map<String, Object> requestParams) {
        // 附加校验
    }

    /**
    * 保存数据
    * @param dataModelList 待保存的数据
    * @param requestParams 请求参数
    */
    @Override
    protected void saveData(List<InstockImportModel> dataModelList, Map<String, Object> requestParams) {
        if (V.isEmpty(dataModelList)) {
            return;
        }
        List<Instock> entityList = BeanUtils.convertList(dataModelList, Instock.class);
        ContextHelper.getBean(InstockService.class).createEntities(entityList);
    }
}